home *** CD-ROM | disk | FTP | other *** search
- situation orbital_squad
- vars
- me : squad;
- my_race : integer;
- my_location : integer;
- target : integer;
- focus : squad;
- loc : integer;
- success : boolean;
- p : planet;
- c_struct : structure;
- b_struct : structure;
-
- begin
- // Find the nearest enemy squad and move toward it
- me := This_squad();
- my_race := Squad_race(me);
- my_location := Squad_hex(me);
- target := -1;
- focus := First_squad(-1);
- while (focus <> nil) do
- begin
- if (Squad_race(focus) <> my_race) then
- begin
- loc := Squad_hex(focus);
- if (target = -1) then
- begin
- target := loc;
- end;
- else
- begin
- if (Planet_distance(my_location, loc) <
- Planet_distance(my_location, target)) then
- target := loc;
- end;
- end;
- focus := Next_squad(focus, -1);
- end;
- if (target = -1) then
- begin
- // if there is no squad, then move toward the nearest structure
- p := This_planet();
- b_struct := First_structure(p);
- if (b_struct = nil) then // If there are no structures then abort
- begin
- success := Move_squad(my_location);
- exit;
- end;
- c_struct := Next_structure(p, b_struct);
- while (c_struct <> nil) do
- begin
- if (Planet_distance(my_location, Structure_hex(p, c_struct)) <
- Planet_distance(my_location, Structure_hex(p, b_struct))) then
- b_struct := c_struct;
- c_struct := Next_structure(p, c_struct);
- end;
- if (b_struct <> nil) then
- begin
- success := Move_squad(Structure_hex(p, b_struct));
- if not success then
- success := Move_squad(my_location);
- end;
- else
- success := Move_squad(my_location);
- end;
- else
- begin
- success := Move_squad(target);
- if (not success) then
- success := Move_squad(my_location);
- end;
- end;
-